package top.timous.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.timous.mapper.student.StudentMapper;
import top.timous.pojo.ScoreEntity;
import top.timous.pojo.StudentEntity;
import top.timous.service.StudentService;
import top.timous.vo.CourseTable;
import top.timous.vo.PageSize;
import top.timous.vo.ScoreTable;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public StudentEntity queryStudentByIdAndPwd(StudentEntity studentEntity) {
        return studentMapper.queryStudentByIdAndPwd(studentEntity);
    }

    @Override
    public StudentEntity queryStudentById(StudentEntity studentEntity) {
        return studentMapper.queryStudentById(studentEntity);
    }

//    @Override
//    public List<CourseTable> queryAllCourse(PageSize pageSize) {
//        return studentMapper.queryAllCourse(pageSize);
//    }

    @Override
    public String queryClassNameById(Integer classId) {
        return studentMapper.queryClassNameById(classId);
    }

    @Override
    public String queryHomeNameById(Integer homeId) {
        return studentMapper.queryHomeNameById(homeId);
    }

    @Override
    public void selectCourse(ScoreEntity scoreEntity) {
        studentMapper.selectCourse(scoreEntity);
    }

    @Override
    public boolean isExistselectCourse(ScoreEntity scoreEntity) {
        int s = studentMapper.isExistselectCourse(scoreEntity);
        return s==1?true:false;
    }

    @Override
    public List<CourseTable> queryAllSelectCourse(PageSize pageSize) {
        // 处理分页操作
        List<CourseTable> list = studentMapper.queryAllSelectCourse((int[]) pageSize.getData());
        int page = pageSize.getPage();
        int size = pageSize.getSize();
        List<CourseTable> list1 = new ArrayList<>();
        int amount = (page * size+size) > list.size() ? list.size() : (page * size+size);
        for (int i = page * size; i < amount; i++) {
            list1.add(list.get(i));
        }
        return list1;
    }

    @Override
    public List<Integer> queryCourseListById(String stuId) {
        return studentMapper.queryCourseListById(stuId);
    }

    @Override
    public List<ScoreTable> queryAllGrade(PageSize pageSize) {
        return studentMapper.queryAllGrade(pageSize);
    }

    @Override
    public int queryAllGradeCount(String stuId) {
        return studentMapper.queryAllGradeCount(stuId);
    }

    @Override
    public List<CourseTable> queryAllCourseByCourseTable(CourseTable courseTable) {
        return studentMapper.queryAllCourseByCourseTable(courseTable);
    }

    @Override
    public int queryAllCourseByCourseTableCount(CourseTable courseTable) {
        return studentMapper.queryAllCourseByCourseTableCount(courseTable);
    }

    @Override
    public void deleteSelectCourse(ScoreEntity scoreEntity) {
        studentMapper.deleteSelectCourse(scoreEntity);
    }

    @Override
    public boolean isExistScore(ScoreEntity scoreEntity) {
        return studentMapper.isExistScore(scoreEntity) == 1;
    }

    @Override
    public void updateStudentPassword(StudentEntity studentEntity) {
        studentMapper.updateStudentPassword(studentEntity);
    }

    @Override
    public int queryAllCourseCount() {
        return studentMapper.queryAllCourseCount();
    }
}
